package com.qijia.common.domain;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.ManyToMany;

import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;

/**
 * AbstractCommonRole entity provides the base persistence definition of the
 * CommonRole entity. @author MyEclipse Persistence Tools
 */
@MappedSuperclass
public abstract class AbstractCommonRole extends BaseData implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 5784940239847295140L;
	private Integer CRoleId;
	private String CRoleName;
	private Set<UserRole> userRoles = new HashSet<UserRole>(0);
	private Set<RoleResource> roleResources = new HashSet<RoleResource>(0);

	// Constructors

	/** default constructor */
	public AbstractCommonRole() {
	}

	/** minimal constructor */
	public AbstractCommonRole(String CRoleName) {
		this.CRoleName = CRoleName;
	}

	/** full constructor */
	public AbstractCommonRole(String CRoleName,
			Set<UserRole> userRoles,
			Set<RoleResource> roleResources) {
		this.CRoleName = CRoleName;
		this.userRoles = userRoles;
		this.roleResources = roleResources;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "c_role_id", unique = true, nullable = false)
	public Integer getCRoleId() {
		return this.CRoleId;
	}

	public void setCRoleId(Integer CRoleId) {
		this.CRoleId = CRoleId;
	}

	@Column(name = "c_role_name", nullable = false, length = 64)
	public String getCRoleName() {
		return this.CRoleName;
	}

	public void setCRoleName(String CRoleName) {
		this.CRoleName = CRoleName;
	}
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "role")
	public Set<RoleResource> getRoleResources() {
		return this.roleResources;
	}

	public void setRoleResources(
			Set<RoleResource> roleResources) {
		this.roleResources = roleResources;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "role")
	public Set<UserRole> getUserRoles() {
		return this.userRoles;
	}

	public void setUserRoles(Set<UserRole> userRoles) {
		this.userRoles = userRoles;
	}
}